package kyc

import (
	privateV1 "code.bydev.io/cht/customer/kyc-stub.git/pkg/bybit/kyc/info/v1"
	"context"

	"code.bydev.io/frameworks/byone/core/logc"
	"git.bybit.com/svc/stub/pkg/pb/api/kyc"
)

type KycSvc = *kycSvc

type kycSvc struct {
	KycInternalClientAPI     kyc.KycInternalClient
	KycInternalClientInfoAPI privateV1.InfoAPIClient
}

func NewKycClient(k kyc.KycInternalClient, kInfo privateV1.InfoAPIClient) KycSvc {
	return &kycSvc{
		KycInternalClientAPI:     k,
		KycInternalClientInfoAPI: kInfo,
	}
}

func (s *kycSvc) UpdateApplicantInfo(ctx context.Context, req *kyc.UpdateApplicantInfoRequest) bool {
	logc.Infow(ctx, "UpdateApplicantInfo request", logc.Field("req", req))
	resp, err := s.KycInternalClientAPI.UpdateApplicantInfo(ctx, req)
	if err != nil {
		logc.Errorw(ctx, "UpdateApplicantInfo error", logc.Field("err", err))
		return false
	}
	logc.Infow(ctx, "UpdateApplicantInfo info", logc.Field("resp", resp))
	if resp.GetError() != nil {
		logc.Errorw(ctx, "UpdateApplicantInfo failed", logc.Field("resp", resp))
		return false
	}
	return true
}

func (s *kycSvc) SetMaintainInfo(ctx context.Context, req *privateV1.SetMaintainInfoRequest) (*privateV1.SetMaintainInfoResponse, error) {
	logc.Infow(ctx, "SetMaintainInfo request", logc.Field("req", req))
	resp, err := s.KycInternalClientInfoAPI.SetMaintainInfo(ctx, req)
	if err != nil {
		logc.Errorw(ctx, "SetMaintainInfo error", logc.Field("err", err))
		return nil, err
	}
	logc.Infow(ctx, "SetMaintainInfo info", logc.Field("resp", resp))
	return resp, nil
}

func (s *kycSvc) GetMaintainInfo(ctx context.Context, req *privateV1.GetMaintainInfoRequest) (*privateV1.GetMaintainInfoResponse, error) {
	logc.Infow(ctx, "GetMaintainInfo request", logc.Field("req", req))
	resp, err := s.KycInternalClientInfoAPI.GetMaintainInfo(ctx, req)
	if err != nil {
		logc.Errorw(ctx, "GetMaintainInfo error", logc.Field("err", err))
		return nil, err
	}
	logc.Infow(ctx, "GetMaintainInfo info", logc.Field("resp", resp))
	return resp, nil
}
